package com.maning.calendarlibrary.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.maning.calendarlibrary.R;
import com.maning.calendarlibrary.constant.MNConst;
import com.maning.calendarlibrary.model.MNCalendarItemModel;
import com.maning.calendarlibrary.model.MNCalendarVerticalConfig;
import com.maning.calendarlibrary.model.MonthModel;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by maning on 2017/5/9.
 */

public class MNCalendarVerticalItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {


    private MonthModel monthModel;
    private ArrayList<MNCalendarItemModel> mDatas;

    private LayoutInflater layoutInflater;

    private Context context;

    private Calendar currentCalendar;

    private MNCalendarVerticalAdapter adapter;

    private String now_yyy_mm_dd;
    private Date nowDate = new Date();
    private CalendarAdapter mCalendarAdapter;
    //配置信息
    private MNCalendarVerticalConfig mnCalendarVerticalConfig;

    public MNCalendarVerticalItemAdapter(Context context, CalendarAdapter calendarAdapter, MonthModel monthModel, ArrayList<MNCalendarItemModel> mDatas, Calendar currentCalendar, MNCalendarVerticalAdapter adapter, MNCalendarVerticalConfig mnCalendarVerticalConfig) {
        this.context = context;
        this.mCalendarAdapter = calendarAdapter;
        this.monthModel = monthModel;
        this.mDatas = mDatas;
        this.currentCalendar = currentCalendar;
        this.adapter = adapter;
        this.mnCalendarVerticalConfig = mnCalendarVerticalConfig;
        layoutInflater = LayoutInflater.from(this.context);

        now_yyy_mm_dd = MNConst.sdf_yyy_MM_dd.format(nowDate);
        try {
            nowDate = MNConst.sdf_yyy_MM_dd.parse(now_yyy_mm_dd);
        } catch (ParseException e) {
            e.printStackTrace();
        }

    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate = layoutInflater.inflate(R.layout.mn_item_calendar_vertical_item, parent, false);
        return new CalendarViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        if (holder instanceof CalendarViewHolder) {

            CalendarViewHolder calendarViewHolder = (CalendarViewHolder) holder;

            MNCalendarItemModel mnCalendarItemModel = mDatas.get(position);

            mCalendarAdapter.bindView(monthModel,mnCalendarItemModel,calendarViewHolder);
        }
    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }


    public  static class CalendarViewHolder extends RecyclerView.ViewHolder {

        public TextView tvDay;
        public TextView tv_small;
        public ImageView iv_bg;

        public CalendarViewHolder(View itemView) {
            super(itemView);
            tvDay = (TextView) itemView.findViewById(R.id.tvDay);
            tv_small = (TextView) itemView.findViewById(R.id.tv_small);
            iv_bg = (ImageView) itemView.findViewById(R.id.iv_bg);
        }
    }

    public static interface CalendarAdapter {

        void bindView(MonthModel monthModel, MNCalendarItemModel mnCalendarItemModel, CalendarViewHolder holder);
    }
}
